package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.MchSetInvitationCodeBean;
import com.shop2cn.iapi.member.service.MchSetInvitationCodeCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmember.MchMemberConfig;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
/**
*商家设置会员邀请制开关
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_MchSetInvitationCode{
	private static MchSetInvitationCodeBean mchsetinvitationcodeBean;
	private static MchSetInvitationCodeCall mchsetinvitationcodeCall;
	GodMemberWapper GodMemberWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商家设置会员邀请制开关");
	}

	@Before
	public void caseUp() {
		mchsetinvitationcodeBean=new MchSetInvitationCodeBean();
		mchsetinvitationcodeCall=new MchSetInvitationCodeCall();
		GodMemberWapper=new GodMemberWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(mchsetinvitationcodeCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchSetInvitationCode_001() {
		Logger.start(true,"商家设置会员邀请制开关成功-一次性");
		try {
			Integer shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.setCollectionMobile(shopid, true);
			mchsetinvitationcodeBean.setShopId(shopid);
			mchsetinvitationcodeBean.setBindType(0);
			mchsetinvitationcodeBean.setInvitationSwitch(true);
			mchsetinvitationcodeCall.setData(mchsetinvitationcodeBean);
			mchsetinvitationcodeCall.callService();			
			Logger.verifyEquals("200", mchsetinvitationcodeCall.getString("code"), "验证code");
			MchMemberConfig db = GodMemberWapper.selectMchMemberConfigByShopId(mchsetinvitationcodeBean.getShopId());
			Logger.verifyEquals(mchsetinvitationcodeBean.getInvitationSwitch(), db.getNeedInvitationCode(), "验证getNeedInvitationCode");
			Logger.verifyEquals(mchsetinvitationcodeBean.getBindType(), db.getBindType(), "验证getBindType");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetInvitationCode_002() {
		Logger.start(true,"shopid不输入失败");
		try {
//			Integer shopid= GodmchManageCallService.CreateSellerMch();
//			GodMemberService.setCollectionMobile(shopid, true);
//			mchsetinvitationcodeBean.setShopId(shopid);
			mchsetinvitationcodeBean.setBindType(0);
			mchsetinvitationcodeBean.setInvitationSwitch(true);
			mchsetinvitationcodeCall.setData(mchsetinvitationcodeBean);
			mchsetinvitationcodeCall.callService();			
			Logger.verifyEquals("400", mchsetinvitationcodeCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetInvitationCode_003() {
		Logger.start(true,"invitationSwitch不输入失败");
		try {
			mchsetinvitationcodeBean.setShopId(1);
			mchsetinvitationcodeBean.setBindType(0);
//			mchsetinvitationcodeBean.setInvitationSwitch(true);
			mchsetinvitationcodeCall.setData(mchsetinvitationcodeBean);
			mchsetinvitationcodeCall.callService();			
			Logger.verifyEquals("400", mchsetinvitationcodeCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetInvitationCode_004() {
		Logger.start(true,"bindType不输入-默认0一次性");
		try {
			Integer shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.setCollectionMobile(shopid, true);
			mchsetinvitationcodeBean.setShopId(shopid);
//			mchsetinvitationcodeBean.setBindType(0);
			mchsetinvitationcodeBean.setInvitationSwitch(true);
			mchsetinvitationcodeCall.setData(mchsetinvitationcodeBean);
			mchsetinvitationcodeCall.callService();			
			Logger.verifyEquals("200", mchsetinvitationcodeCall.getString("code"), "验证code");
			MchMemberConfig db = GodMemberWapper.selectMchMemberConfigByShopId(mchsetinvitationcodeBean.getShopId());
			Logger.verifyEquals(mchsetinvitationcodeBean.getInvitationSwitch(), db.getNeedInvitationCode(), "验证getNeedInvitationCode");
			Logger.verifyEquals(0, db.getBindType(), "验证getBindType");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetInvitationCode_005() {
		Logger.start(true,"只有开启绑定手机号的商家可以开启会员邀请制开关");
		try {
			Integer shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.setCollectionMobile(shopid, false);
			mchsetinvitationcodeBean.setShopId(shopid);
			mchsetinvitationcodeBean.setBindType(1);
			mchsetinvitationcodeBean.setInvitationSwitch(true);
			mchsetinvitationcodeCall.setData(mchsetinvitationcodeBean);
			mchsetinvitationcodeCall.callService();			
			Logger.verifyEquals("300", mchsetinvitationcodeCall.getString("code"), "验证code");
			MchMemberConfig db = GodMemberWapper.selectMchMemberConfigByShopId(mchsetinvitationcodeBean.getShopId());
			Logger.debug(FormatUtil.beanToGSONString(db));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	@Ignore
	//使用新接口MchSetBindType
	public void Tc_MchSetInvitationCode_006() {
		Logger.start(true,"商家设置会员邀请制开关成功-永久");
		try {
			Integer shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.setCollectionMobile(shopid, true);
			mchsetinvitationcodeBean.setShopId(shopid);
			mchsetinvitationcodeBean.setBindType(1);
			mchsetinvitationcodeBean.setInvitationSwitch(true);
			mchsetinvitationcodeCall.setData(mchsetinvitationcodeBean);
			mchsetinvitationcodeCall.callService();			
			Logger.verifyEquals("200", mchsetinvitationcodeCall.getString("code"), "验证code");
			MchMemberConfig db = GodMemberWapper.selectMchMemberConfigByShopId(mchsetinvitationcodeBean.getShopId());
			Logger.debug(FormatUtil.beanToGSONString(db));
			Logger.verifyEquals(mchsetinvitationcodeBean.getInvitationSwitch(), db.getNeedInvitationCode(), "验证getNeedInvitationCode");
			Logger.verifyEquals(mchsetinvitationcodeBean.getBindType(), db.getBindType(), "验证getBindType");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetInvitationCode_007() {
		Logger.start(true,"只有开启绑定手机号的商家可以开启会员邀请制开关-没有记录");
		try {
			Integer shopid= GodmchManageCallService.CreateSellerMch();
//			GodMemberService.setCollectionMobile(shopid, false);
			mchsetinvitationcodeBean.setShopId(shopid);
			mchsetinvitationcodeBean.setBindType(1);
			mchsetinvitationcodeBean.setInvitationSwitch(true);
			mchsetinvitationcodeCall.setData(mchsetinvitationcodeBean);
			mchsetinvitationcodeCall.callService();			
			Logger.verifyEquals("300", mchsetinvitationcodeCall.getString("code"), "验证code");
//			MchMemberConfig db = GodMemberWapper.selectMchMemberConfigByShopId(mchsetinvitationcodeBean.getShopId());
//			Logger.debug(FormatUtil.beanToGSONString(db));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}